/****************************************************************************
Copyright (c) 2010-2013 cocos2d-x.org
Copyright (c) Microsoft Open Technologies, Inc.

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/


#ifndef GAMELAYER_H
#define GAMELAYER_H

#include "cocos2d.h"
//#include "game.h"
#include "GameModel.h"
#include "MainGameScene.h"

USING_NS_CC;
using namespace std;
using namespace cocos2d;

///@brief Ui module to show game.
class  GameLayer: public CCLayer
{
public:
    GameLayer();
    virtual ~GameLayer();

    ///@brief create sprites and place them by the game initiation data.
    ///@param border border show in ui.
    ///@param srcborder the border of backgound sprite.
    ///@param imgPath file path of the backgound sprite.
    ///@param model data of game.
    bool initModel(float border,float srcborder,char* imgPath,GameModel* model);

    ///@brief The player click specific row and col
    ///@param row row in game chess board.
    ///@param col col in game chess board.
    bool onClick(int row,int col);

    ///@brief Callback when touch.
    virtual bool ccTouchBegan(CCTouch *pTouch,CCEvent *pEvent);

    virtual void registerWithTouchDispatcher();

    virtual void onEnter();

    CREATE_FUNC(GameLayer);

protected:
private:
    GameModel* _model; ///<game board data.
    float _border; ///<game show border
    char* _imgPath; ///<current game picture path

    bool isWin; ///<
};


class GameSprite:public CCSprite, public CCTouchDelegate{
public:
    virtual bool init();

    GameLayer* parent;

    virtual bool ccTouchBegan(CCTouch *pTouch,CCEvent *pEvent);

    CREATE_FUNC(GameSprite);

    int row;
    int col;
    int data;

};


#endif // GAMELAYER_H
